<?php

/**
 * @author ducnhat
 * @email ddnhat@gmail.com
 * @copyright 2014
 */

class Admin_Form_ValidateBrand{
	
    protected $_isError = false;
	protected $_messageError = null;
    protected $_arrData = null;
    protected $_classError = null;
    
    public function __construct($params = array(), $edit = false, $data = null){
        
        $translate = Zend_Registry::get('Zend_Translate');
        
        $validateBrand = new Zend_Validate();
        $validateDescription = new Zend_Validate();
        
        $option = array('table' => 'brands', 'field' => 'id');
        
        $validateBrand->addValidator(new Zend_Validate_NotEmpty, true)
                        ->addValidator(new Zend_Validate_Alnum(true), true)
                        ->addValidator(new Zend_Validate_StringLength(array('max' => 50)), true)
                        ->addValidator(new Zend_Validate_Db_NoRecordExists($option), true);
        
        /*
        * Check Brand
        */
        
        if(!$validateBrand->isValid($params['brand'])){
            $this->_messageError['brand'] = '<label class="control-label" for="inputError">' . $translate->_('brand') . current($validateBrand->getMessages()) . '</label>';
            $this->_arrData['brand'] = '';
            $this->_classError['brand'] = 'has-error';
            $this->_isError = true;
            
            if($edit){
                $this->_arrData['brand'] = $data['brand'];
            }
        }else{
            $this->_messageError['brand'] = '';
            $this->_arrData['brand'] = $params['brand'];
            $this->_classError['brand'] = '';
        }
        
        if($edit){
            $this->_arrData['id'] = $data['id'];
        }
    }
    
    public function isError(){
    	return $this->_isError;
    }
    
    public function getMessageError(){
        return $this->_messageError;
    }
    
    public function getClassError(){
    	return $this->_classError;
    }
    
    public function getData(){
        return $this->_arrData;
    }
}